<!-- Dom模板 -->
<template>
  <div id="box">
    <!-- 头部 -->
    <div class="header">
      <!-- iconfont -->
      <div class="top">
        <div>
          <i @click="goHo" class="iconfont icon-lt"></i>
        </div>
      </div>
      <!-- 标题 -->
      <div class="center">
        <div class="img">
          <img
            :class="bookItem.navType != 1 ? 'cover' : ''"
            :src="bookItem.bookImg"
            v-if="trueimg"
            :id="bookItem.bookImg === trueimg ? 'yes' : ''"
          />
        </div>
        <div class="content">
          <h4>
            {{ bookItem.bookName }}
            <button @click="favor" :class="choose ? 'new' : 'end'">
              {{ content }}
            </button>
          </h4>
          <h5>{{ bookItem.storyIntroduced }}</h5>
          <div>
            <p>{{ bookItem.bookAim }}</p>
            <p>适合年龄段: {{ bookItem.age }}</p>
          </div>
          <!-- {{ $store.state.order.dingyue.item }} -->
        </div>
      </div>
      <!-- 评论 -->
      <ul class="bottom">
        <li>
          <i class="iconfont icon-xiaoxi-weixuanzhong"></i>
          <p>{{ pingLunNumber }}</p>
        </li>
        <li>
          <i class="iconfont icon-fenxiang1"></i>
          <p>{{ bookItem.shareNumber }}</p>
        </li>
        <li>
          <i class="iconfont icon-erji"></i>
          <p>{{ bookItem.playNumber / 10000 }}万次</p>
        </li>
      </ul>
    </div>
    <!-- 会员 -->
    <div class="memberBox">
      <div>
        <img src="../../../../../static/img/图片 2 Copy@1x.png" />
        <a>Moco会员</a><span>畅听千万新故事</span>
      </div>
      <div>
        <span @click="goVIP()">{{
          this.yuan == "1" ? "已是会员" : "立即开通"
        }}</span>
        <i class="iconfont icon-arrow-left"></i>
      </div>
    </div>
    <!-- 播放全部 -->
    <div class="contentBox">
      <div class="top">
        <i @click="goPlay(bookItem)" class="iconfont icon-bofang1"></i>
        <p @click="goPlay(bookItem)">
          播放全部<span>(共{{ bookData.length }}集)</span>
        </p>
        <button @click="goDetail(bookItem)">故事详情</button>
      </div>
      <ul>
        <li
          class="animate__animated animate__bounceInUp"
          v-for="(item, index) in bookData"
          :style="{
            animationDelay: `${(index + 1) * 0.03}s`,
            animationDuration: '0.85s',
          }"
          :key="index"
        >
          <span @click="goPlay(item, index)">{{ index + 1 }}</span>
          <a @click="goPlay(item, index)"
            >{{ bookItem.bookName }}--{{ item.name }}</a
          >

          <i
            class="iconfont icon--"
            v-show="item.tupian == '1' && yuan == '0'"
            @click="buy(item, index)"
          ></i>
          <i v-show="yuan == '1'" @click="buy"></i>
        </li>
      </ul>
    </div>
    <!-- 尾部 -->
    <div class="footer animate__animated animate__bounceInUp">
      <div class="buy" @click="buy">购买专辑</div>
      <div class="vip" @click="goVIP">成为畅听会员</div>
    </div>
    <div v-if="alertFlag" @click="close" class="meng"></div>
    <transition name="top">
      <BuyAlert
        class="hua"
        :itemJi="itemJi"
        :bookId="bookId"
        :yuan="yuan"
        :bookData="bookData"
        v-if="alertFlag"
        @close="close1"
      ></BuyAlert>

      <VipTan @closed="closed" v-if="vipFlag"> </VipTan>
    </transition>
    {{ shujua }}
    <BalanceTan v-if="deficiency" @guanbi="guanbi"></BalanceTan>
  </div>
</template>

<script>
// import a from './a'; // 引入组件
import * as api from "../../../api/home";
import Tan from "../../home_notregister/tan/tan.vue";
import BuyAlert from "./buyAlert.vue";
import AllBuyAlert from "./allBuyAlert.vue";
import BalanceTan from "./balanceTan.vue";
import VipTan from "./vipTan.vue";
export default {
  components: { BuyAlert, Tan, AllBuyAlert, BalanceTan, VipTan },
  data() {
    return {
      msg: "测试",
      bookData: [],
      bookItem: {},
      bookId: "",
      alertFlag: false,
      yuan: "",
      itemJi: "",
      deficiency: false,
      pingLunNumber: 0,
      choose: false,
      content: "+订阅",
      bg_color: "#ffffff",
      ft_color: "black",
      itemDy: [],
      phone: "",
      trueimg: "http://192.168.1.128:8888/img/图片 5 Copy 2@1x (1).png",
      add: {},
      vipFlag: false,
    };
  }, // 生命周期 - 创建完成（访问当前this实例）
  computed: {
    shujua() {
      api.userData().then((res) => {
        console.log(res.data.code[1].shuju);
      });
    },
  },
  created() {}, // 生命周期 - 挂载完成（访问DOM元素）
  mounted() {
    this.phone = this.$store.state.order.user.title;
    this.bookId = this.$route.params.id;
    console.log(333, this.$store.state.order.type);
    this.choose = this.$store.state.order.type;
    console.log(444, this.choose);
    if (this.choose) {
      this.content = "已订阅";
    } else {
      this.content = "+订阅";
    }
    api
      .chaxunTitle({ dian: this.$store.state.order.user.title })
      .then((res) => {
        this.yuan = res.data.code;
        this.bookId = this.$route.params.id;
        api
          .toStoryDetail({ bookId: this.bookId })
          .then((res) => {
            console.log("成功", res);
            this.bookData = res.data;
            this.bookItem = res.data[0];
          })
          .catch((err) => {
            console.log("失败", err);
          });
        console.log("成功", res);
      })
      .catch((err) => {
        console.log("失败", err);
      });
    api.pingLunNumber({ bookId: this.bookId }).then((res) => {
      this.pingLunNumber = res.data.pingLunNumber;
    });
    // api
    //   .tianjia({
    //     id: this.bookId,
    //     itemPhone: this.phone,
    //     itemBook: this.itemDy.bookName,
    //     ami: this.itemDy.bookAim,
    //     img: this.itemDy.bookImg,
    //     name: this.itemDy.bookName,

    //   })
    //   .then((res) => {
    //     console.log("添加接口", res, "lalalla");
    //   });
  }, // Vue方法定义
  methods: {
    goHo() {
      this.$router.push("/home");
    },
    goVIP() {
      this.$router.push({
        path: `/giveFriend`,
      });
    },
    goPlay(item, index) {
      console.log(item);
      if (this.yuan == "1") {
        this.$router.push({
          path: "/tgs",
          query: { episode: JSON.stringify(item) },
        });
        this.$store.commit("chat/playEvent", true);
      } else if (item.tupian == "0") {
        this.$router.push({
          path: "/tgs",
          query: { episode: JSON.stringify(item) },
        });
        this.$store.commit("chat/playEvent", true);
      }
    },
    goDetail() {
      this.$router.push({
        path: `/gsjs/${this.bookId}`,
      });
    },
    buy(item, index) {
      if (this.yuan == "1") {
        this.vipFlag = true;
      } else {
        this.alertFlag = true;
      }
      this.itemJi = item;
    },
    close() {
      this.alertFlag = false;
    },
    closed(res) {
      this.vipFlag = false;
    },
    guanbi() {
      this.deficiency = false;
    },
    favor() {
      this.choose = !this.choose;
      this.$store.commit("order/choose", this.choose);
      // console.log(111111, this.$store.state.order.type);
      console.log(222222, this.choose);
      if (this.choose) {
        this.content = "已订阅";
        this.itemDy = this.bookItem;
        let arr = {};
        arr = {
          name: this.itemDy.bookName,
          img: this.itemDy.bookImg,
          aim: this.itemDy.bookAim,
        };
        api
          .tianjia({
            id: this.bookId,
            itemBook: this.bookId,
            itemPhone: this.phone,
            ami: this.itemDy.bookAim,
            img: this.itemDy.bookImg,
            name:this.itemDy.bookName
          })
          .then((res) => {
            this.add = res.config.data;
            this.$store.commit("order/dy", {
              item: this.add,
            });
            console.log("测试", res);
            console.log("添加接口1", this.add, "lalalla");
            console.log("添加接口2", res.config.data, "lalalla");
          })
          .catch((err) => {
            console.log("2222222222222222222222222", err);
          });
        console.log("内容", arr);
        console.log("订阅", this.itemDy);
      } else {
        this.content = "+订阅";
        let arr = {};
        arr = {
          name: this.itemDy.bookName,
          img: this.itemDy.bookImg,
          aim: this.itemDy.bookAim,
        };
        // if (arr.name === this.itemDy.bookName) {
          api
            .deletedingStory({ itemBook: this.bookId })
            .then((res) => {
              console.log("取消订阅", res);
            })
            .catch((err) => {
              console.log(this.bookId);
              console.log("删除失败", err);
            });
        // }
      }
      // this.$store.dispatch("order/dy", this.choose);
      // console.log(this.$store.state.order.dingyue);

      console.log(this.choose);
    },
    change() {
      this.bg_color = "#ff9999";
      this.ft_color = "#fef0f0";
    },
    goback() {
      if (this.choose) {
        this.bg_color = "#ff9999";
        this.ft_color = "#fef0f0";
      } else {
        this.bg_color = "#fef0f0";
        this.ft_color = "black";
      }
    },
    close1(res) {
      api.toStoryDetail({ bookId: this.bookId }).then((res) => {
        console.log("成功", res);
        this.bookData = res.data;
        this.bookItem = res.data[0];
      });
      this.deficiency = res.flags;
      this.alertFlag = res.flag;
    },
  },
};
</script>

<style scoped>
/* @import url(); 引入css类 */
@import url("../../../../assets/font/iconfont.css");

#box {
  position: relative;
  height: 100vh;
  overflow: hidden;
  background: white;
  z-index: 999;
}
/* 头部 */
.header {
  width: 100vw;
  height: 428px;
  background: #00b397;
  padding-top: 40px;
}
/* 头部的顶部 */
.header .top {
  width: 100vw;
  height: 4px;
  display: flex;
  justify-content: space-between;
  padding: 0 14px;
  align-items: center;
  vertical-align: middle;
}
.header .top .icon-lt {
  font-size: 24px;
  color: white;
  font-weight: bold;
}
.header .top p {
  width: 87px;
  height: 32px;
  line-height: 20px;
  border-radius: 30px;
  background-color: #00b297;
  text-align: center;
  border: 1px solid rgba(232, 232, 232, 100);
  display: flex;
  justify-content: space-evenly;
  align-items: center;
}
.header .top p span {
  border-right: 2px solid #e8e8e8;
  display: block;
  width: 1px;
  height: 18px;
}
.header .center .content h4 button {
  background: #ffffff;
  border: none;
  border-radius: 15px;
  padding: 5px 10px;
}
.header .top p .icon-sandian {
  color: white;
  font-size: 20px;
  font-weight: bold;
}
.header .top p .icon-xiaochengxu-guanbi1 {
  color: white;
  font-size: 15px;
  font-weight: bold;
  vertical-align: middle;
}
/* 头部图片 */
.header .center {
  margin-top: 40px;
  padding: 0 27px;
  height: 100px;
  width: 100vw;
  display: flex;
  justify-content: left;
  align-items: center;
}
.header .center .img {
  height: 100px;
  width: 100px;
  background: #00e6c3;
  border-radius: 26px;
  position: relative;
  overflow: hidden;
}
.header .center .img img {
  position: absolute;
  bottom: 0;
  width: 67.2px;
  left: 50px;
  transform: translateX(-50%);
}
.header .center .img .cover {
  position: absolute;
  top: 0px;
  width: 107%;
  left: 50px;
}
/* 右边的内容 */
.header .center .content {
  margin-left: 20px;
  color: white;
}
.header .center .content h4 {
  font-size: 19px;
}
.header .center .content h5 {
  font-size: 14px;
  margin-top: 6px;
}
.header .center .content div {
  margin-top: 19px;
}
.header .center .content p {
  font-size: 12px;
  color: rgba(255, 255, 255, 100);
  opacity: 0.5;
}
.header .center .content .new {
  background: orange;
  color: white;
}
.header .center .content .end {
  background: #ccc;
}
/* 头部的尾部 */
.header .bottom {
  margin-top: 17px;
  height: 50px;
  display: flex;
  justify-content: space-evenly;
  align-items: center;
}
.header .bottom li {
  float: left;
  padding: 0 22px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: white;
}
.header .bottom li .iconfont {
  font-size: 21px;
  margin-bottom: 2px;
}
/* 会员 */
.memberBox {
  width: 100vw;
  height: 167px;
  background: #7fd9cb;
  position: absolute;
  top: 268.9px;
  border-radius: 26px;
  display: flex;
  justify-content: space-between;
  vertical-align: middle;
  padding: 10px 15px;
  color: white;
  animation: top 0.85s;
}
@keyframes top {
  0% {
    transform: translateY(100%);
  }
  50% {
    transform: translateY(0%);
  }
  70% {
    transform: translateY(5%);
  }
  100% {
    transform: translateY(0%);
  }
}
.memberBox img {
  vertical-align: middle;
}
.memberBox a {
  margin-left: 7px;
  font-size: 16px;
  font-weight: bold;
}
.memberBox span {
  margin-left: 9px;
  font-size: 12px;
}
.memberBox i {
  font-size: 20px;
  vertical-align: middle;
}

/* 底部内容样式 */
.contentBox {
  width: 100vw;
  height: 515px;
  background: #ffffff;
  position: absolute;
  top: 312px;
  border-radius: 26px 26px 26px 26px;
  padding: 0 18px;
  animation: top1 0.8s;
}
@keyframes top1 {
  0% {
    opacity: 0;
    transform: translateY(100%);
  }
  50% {
    opacity: 1;
    transform: translateY(0%);
  }
  70% {
    transform: translateY(5%);
  }
  100% {
    transform: translateY(0%);
  }
}
.contentBox .top {
  margin-top: 16px;
  width: 100%;
  height: 26px;
  vertical-align: middle;
  line-height: 26px;
  overflow: hidden;
}
.contentBox .top .icon-bofang1 {
  float: left;
  font-size: 26px;
}
.contentBox .top p {
  float: left;
  margin-left: 10px;
  font-size: 16px;
  color: #000000;
  vertical-align: middle;
}
.contentBox .top p span {
  font-size: 12px;
  color: #9f9f9f;
  margin-left: 10px;
  vertical-align: middle;
}
.contentBox .top button {
  float: right;
  height: 100%;
  border: none;
  width: 90px;
  color: white;
  background: #ff0056;
  border-radius: 50px;
  text-align: 12px;
}
/* 我家来外星人了 */
.contentBox ul {
  margin-top: 2px;
  width: 100%;
  padding-left: 10px;
}
.contentBox ul li {
  line-height: 37px;
  width: 100%;
  font-size: 14px;
}
.contentBox ul li span {
  color: #9f9f9f;
  padding-right: 10px;
}
.contentBox ul li i {
  float: right;
  color: #ff3d03;
  font-size: 30px;
}
/* 底部样式 */
.footer {
  width: 100vw;
  height: 49.2px;
  position: absolute;
  bottom: 0;
}
.footer div {
  width: 50vw;
  height: 49.2px;
  float: left;
  text-align: center;
  line-height: 49.2px;
  color: white;
}
.footer .buy {
  background: #ff7100;
  border-radius: 26px 0px 0px 0px;
}
.footer .vip {
  background: #fe0056;
  border-radius: 0px 26px 0px 0px;
}
/* 动画 */
.center {
  margin-top: 40px;
  padding: 0 27px;
  height: 100px;
  width: 100vw;
  display: flex;
  justify-content: left;
  align-items: center;
  animation: tops 1s 1 cubic-bezier(0.215, 0.61, 0.355, 1);
}
.bottom {
  animation: topes 1.1s 1 cubic-bezier(0.215, 0.61, 0.355, 1);
}
@keyframes tops {
  0% {
    opacity: 0;
    transform: translateY(-3000px);
  }
  60% {
    opacity: 1;
    transform: translateY(25px);
  }
  75% {
    transform: translateY(-10px);
  }
  90% {
    transform: translateY(5px);
  }
  100% {
    transform: none;
  }
}
@keyframes topes {
  0% {
    opacity: 0;
    transform: translateY(-3000px);
  }
  60% {
    opacity: 1;
    transform: translateY(25px);
  }
  75% {
    transform: translateY(-10px);
  }
  90% {
    transform: translateY(5px);
  }
  100% {
    transform: none;
  }
}
.top-enter {
  transform: translateY(100vh);
}
.top-leave-to {
  transform: translateY(100%);
}
.hua {
  transition: all 0.5s;
}
.meng {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
}
#yes {
  position: absolute;
  top: 0;
  height: 100%;
  width: 107%;
  left: 40px;
}
</style>